package com.dc.commons.persistence.embeddable;

import java.io.File;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;

import com.dc.commons.sys.persistence.IAttachment;
import com.fasterxml.jackson.annotation.JsonIgnore;

/*******************************************************************************<P>
 * 文件名: Attachment.java <br>
 * 版本: 1.0<br>
 * 描述: 附件<br>
 * 版权所有: <br>
 * <P>
 * 创建者: 王建栋 <br>
 * 创建日期: 2016年6月2日 下午5:54:00<br>
 * 修改者: <br>
 * 修改日期: <br>
 * 修改说明: <br>
 ******************************************************************************/
@Embeddable
public class Attachment implements IAttachment {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	

	private String Id;
	
	private String name;
	private String type;
	private String link;

	@Column(name="ID",length=200)
	public String getId() {
		return Id;
	}

	public void setId(String id) {
		Id = id;
		
		//FIXME 在这里做缓存
	}

	/* (non-Javadoc)
	 * @see com.dc.commons.sys.persistence.Attachment#getName()
	 */
	@Override
	@Transient
	public String getName() {
		return this.name;
	}

	/* (non-Javadoc)
	 * @see com.dc.commons.sys.persistence.Attachment#setName(java.lang.String)
	 */
	@Override
	public void setName(String name) {
		this.name=name;
	}

	/* (non-Javadoc)
	 * @see com.dc.commons.sys.persistence.Attachment#getType()
	 */
	@Override
	@Transient
	public String getType() {
		return this.type;
	}

	/* (non-Javadoc)
	 * @see com.dc.commons.sys.persistence.Attachment#setType(java.lang.String)
	 */
	@Override
	public void setType(String type) {
		this.type=type;
	}

	/* (non-Javadoc)
	 * @see com.dc.commons.sys.persistence.Attachment#getLink()
	 */
	@Override
	@Transient
	public String getLink() {
		return this.link;
	}

	/* (non-Javadoc)
	 * @see com.dc.commons.sys.persistence.Attachment#setLink(java.lang.String)
	 */
	@Override
	public void setLink(String link) {
		this.link=link;
	}
	
	@Transient
	@JsonIgnore
	public File getFile(){
		return new File(link);
	}

}
